package com.hoshino.momochi.service.Impl;

import com.hoshino.momochi.mapper.UserDetailsMapper;
import com.hoshino.momochi.model.domain.UserDetails;
import com.hoshino.momochi.service.UserDetailsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.Future;

@Service
@Slf4j
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private UserDetailsMapper userDetailsMapper;

    @Override
    public void updateMail(UserDetails userDetails) {
        userDetailsMapper.updateMail(userDetails);
    }

    @Override
    public void updateUserIp(UserDetails userDetails) {
        userDetailsMapper.updateUserIp(userDetails);
    }

    @Override
    public void addUserDetails(UserDetails userDetails) {
        userDetailsMapper.addUserDetails(userDetails);
    }

    @Override
    public void delUserDetails(Long uid) {
        userDetailsMapper.delUserDetails(uid);
    }

    @Override
    @Async
    public Future<UserDetails> getUserDetails(Long uid) {
        UserDetails res = userDetailsMapper.getUserDetails(uid);
        return new AsyncResult<>(res);
    }

    @Override
    public UserDetails getUserDetailsNAsync(Long uid) {
        return userDetailsMapper.getUserDetails(uid);
    }

    @Override
    public void updateUrl(UserDetails userDetails) {
        userDetailsMapper.updateUrl(userDetails);
    }

    @Override
    public void updateUserDetailsNew(UserDetails userDetails) {
        userDetailsMapper.updateUserDetailsNew(userDetails);
    }

    @Override
    public void delIsDeleteAsTrue() {
        userDetailsMapper.delIsDeleteAsTrue();
    }

    @Override
    public Long checkMailIsNull(String mail) {
        return userDetailsMapper.checkMailIsNull(mail);
    }

    @Override
    @Async
    public Future<List<UserDetails>> getLocalUserDetails(Long focus_id) {
        List<UserDetails> res = userDetailsMapper.getLocalUserDetails(focus_id);
        return new AsyncResult<>(res);
    }

    @Override
    @Async
    public Future<List<UserDetails>> getFocusUserDetails(Long local_id) {
        List<UserDetails> res = userDetailsMapper.getFocusUserDetails(local_id);
        return new AsyncResult<>(res);
    }
}
